package com.ctsi.ssdc.controller;

import com.ctsi.ssdc.entity.Excel08;
import com.ctsi.ssdc.entity.Excel08VO.*;
import com.ctsi.ssdc.entity.IndustrialEconomicIndicators;
import com.ctsi.ssdc.service.Excel08Service;
import com.ctsi.ssdc.service.ExcelService;
import io.swagger.annotations.ApiOperation;
import org.jsoup.helper.StringUtil;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.web.PageableDefault;
import org.springframework.http.ResponseEntity;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import scala.Int;

import javax.annotation.Resource;
import java.util.List;

/**
 * 8基础表工业分行业(产值能耗)(Excel08)表控制层
 *
 * @author makejava
 * @since 2023-03-15 15:11:26
 */
@RestController
@RequestMapping("excel/08")
public class Excel08Controller {
    /**
     * 服务对象
     */
    @Resource
    private Excel08Service excel08Service;
    @Resource
    private ExcelService excelService;

    /**
     * 分页查询
     *
     * @param excel08 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @GetMapping
    public ResponseEntity<Page<Excel08>> queryByPage(Excel08 excel08,@PageableDefault(page = 0, size = 50) Pageable pageRequest) {
        return ResponseEntity.ok(this.excel08Service.queryByPage(excel08,(PageRequest) pageRequest));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<Excel08> queryById(@PathVariable("id") Long id) {
        return ResponseEntity.ok(this.excel08Service.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param excel08 实体
     * @return 新增结果
     */
    @PostMapping
    @Transactional(rollbackFor = Exception.class)
    public ResponseEntity<Excel08> add(Excel08 excel08) {
        Excel08 insert = this.excel08Service.insert(excel08);
        excelService.sheet8Cal(excel08.getStatisticalTime());
        return ResponseEntity.ok(insert);
    }

    /**
     * 编辑数据
     *
     * @param excel08 实体
     * @return 编辑结果
     */
    @PutMapping
    @Transactional(rollbackFor = Exception.class)
    public ResponseEntity<Excel08> edit(Excel08 excel08) {
        Excel08 update = this.excel08Service.update(excel08);
        excelService.sheet8Cal(excel08.getStatisticalTime());
        return ResponseEntity.ok(update);
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    @Transactional(rollbackFor = Exception.class)
    public ResponseEntity<Boolean> deleteById(Long id) {
        Excel08 excel08 = excel08Service.queryById(id);
        boolean res = this.excel08Service.deleteById(id);
        excelService.sheet8Cal(excel08.getStatisticalTime());
        return ResponseEntity.ok(res);
    }


    /**
     * 根据法人或集团信息获取一个月的公司数据
     * 重点工业企业产值完成情况
     * @param year
     * @param month
     * @param group 类型0:按集团搜索 1:按法人搜索
     * @return
     */
    @ApiOperation("根据法人或集团信息获取一个月的公司数据")
    @GetMapping("info/{year}/{month}/{group}")
    public ResponseEntity<List<Excel08VO>> getInfo(@PathVariable("year") String year, @PathVariable("month") String month, @PathVariable("group") Integer group) {
        return ResponseEntity.ok(this.excel08Service.getInfo(year,month,group));
    }

    /**
     * 根据年份,集团或法人名称获取每个月的公司数据
     * @param year
     * @param name 集团 或 法人名称
     * @param apiType 0: 集团 1: 法人
     * @return
     */
    @ApiOperation("根据年份,集团或法人名称获取每个月的公司数据")
    @GetMapping("infoYear/{year}/{name}/{apiType}")
    public ResponseEntity<List<MonthProductVo>> getInfoYear(@PathVariable("year") String year,
                                                            @PathVariable("name") String name,
                                                            @PathVariable("apiType") Integer apiType) {
        return ResponseEntity.ok(this.excel08Service.getInfoYear(year,name,apiType));
    }


    /**
     * 获取一个月公司按照行业分类的数据
     * 规模以上工业分行业产值
     * @param year
     * @param month
     * @return
     */
    @ApiOperation("获取一个月公司按照行业分类的数据")
    @GetMapping("info/{year}/{month}")
    public ResponseEntity<List<Excel08VO>> getInfoType(@PathVariable("year") String year,
                                                       @PathVariable("month") String month) {
        return ResponseEntity.ok(this.excel08Service.getInfoType(year,month));
    }


    /**
     * 查询重点企业
     * @param year
     * @param month
     * @return
     */
    @ApiOperation("查询重点企业")
    @GetMapping("keyInfo/{year}/{month}")
    public ResponseEntity<List<Excel08VO>> getKeyInfo(@PathVariable("year") String year,
                                                      @PathVariable("month") String month) {

        return ResponseEntity.ok(this.excel08Service.getKeyInfo(year,month));
    }

    /**
     * 获取规上工业总产值当月 + 累计 + 同比
     * @param year
     * @param month
     * @return
     */
    @ApiOperation("获取规上工业总产值当月 + 累计 + 同比")
    @GetMapping("industryOutputInfo/{year}/{month}")
    public ResponseEntity<IndustrialEconomicIndicators> getIndustryOutputInfo(@PathVariable("year") String year,
                                                                                    @PathVariable("month") String month) {
        return ResponseEntity.ok(this.excel08Service.getIndustryOutputInfo(year,month));
    }

    /**
     * 获取综合能源消费量（吨标准煤）当月 + 累计 + 同比
     * @param year
     * @param month
     * @return
     */
    @ApiOperation("获取综合能源消费量（吨标准煤）当月 + 累计 + 同比")
    @GetMapping("energyConsumptionInfo/{year}/{month}")
    public ResponseEntity<IndustrialEconomicIndicators> getEnergyConsumptionInfo(@PathVariable("year") String year,
                                                                              @PathVariable("month") String month) {
        return ResponseEntity.ok(this.excel08Service.getEnergyConsumptionInfo(year,month));
    }

    /**
     * 获取规上工业用电量（万千瓦时）当月 + 累计 + 同比
     * @param year
     * @param month
     * @return
     */
    @ApiOperation("获取规上工业用电量（万千瓦时）当月 + 累计 + 同比")
    @GetMapping("industrialElectricityInfo/{year}/{month}")
    public ResponseEntity<IndustrialEconomicIndicators> getIndustrialElectricityInfo(@PathVariable("year") String year,
                                                                               @PathVariable("month") String month) {
        return ResponseEntity.ok(this.excel08Service.getIndustrialElectricityInfo(year,month));
    }

    /**
     * 获取万元产值能耗（吨标准煤/万元）当月 + 累计 + 同比
     * @param year
     * @param month
     * @return
     */
    @ApiOperation("获取万元产值能耗（吨标准煤/万元）当月 + 累计 + 同比")
    @GetMapping("energyConsumption1wInfo/{year}/{month}")
    public ResponseEntity<IndustrialEconomicIndicators> getEnergyConsumption1wInfo(@PathVariable("year") String year,
                                                                                 @PathVariable("month") String month) {
        return ResponseEntity.ok(this.excel08Service.getEnergyConsumption1wInfo(year,month));
    }

    /**
     * 获取高新技术产业产值当月 + 累计 + 同比
     * @param year
     * @param month
     * @return
     */
    @ApiOperation("获取高新技术产业产值当月 + 累计 + 同比")
    @GetMapping("HighTechInfo/{year}/{month}")
    public ResponseEntity<IndustrialEconomicIndicators> getHighTechInfo(@PathVariable("year") String year,
                                                                         @PathVariable("month") String month) {
        return ResponseEntity.ok(this.excel08Service.getHighTechInfo(year,month));
    }


    /**
     * 获取高新占比当月 + 累计 + 同比
     * @param year
     * @param month
     * @return
     */
    @ApiOperation("获取高新占比当月 + 累计 + 同比")
    @GetMapping("HighTechProportionInfo/{year}/{month}")
    public ResponseEntity<IndustrialEconomicIndicators> getHighTechProportionInfo(@PathVariable("year") String year,
                                                                        @PathVariable("month") String month) {
        return ResponseEntity.ok(this.excel08Service.getHighTechProportionInfo(year,month));
    }






}

